import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * https://gitee.com/li--jiaqiang/java-test.git
 * git pull
 * git pull origin master
 * git pull origin master --allow-unrelated-histories
 * User: 86187
 * Date: 2022-05-15
 * Time: 18:23
 */

//Scanner scan = new Scanner(System.in);

class Students {
    public int age;
    public String name;
    public double scores;

    public Students(int age, String name, double scores) {
        this.age = age;
        this.name = name;
        this.scores = scores;
    }

    @Override
    public String toString() {
        return "Test2{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", scores=" + scores +
                '}';
    }
}

//年龄比较器
class AgeComparator implements Comparator<Students> {
    @Override
    public int compare(Students o1, Students o2) {
        return o1.age - o2.age;
    }
}



public class Test2 {

    public static void main(String[] args) {
        Students[] students = new Students[3];
        students[0] = new Students(15,"bit",76.4);
        students[1] = new Students(23,"asd",86.4);
        students[2] = new Students(18,"gb",68.4);
        System.out.println("排序前"+ Arrays.toString(students));
        AgeComparator ageComparator = new AgeComparator();
        Arrays.sort(students,ageComparator);
        System.out.println("排序前"+Arrays.toString(students));
    }

    public static void main1(String[] args) {

        Students student1 = new Students(15,"bit",96.7);
        Students student2 = new Students(19,"abc",86.7);

        AgeComparator ageComparator = new AgeComparator();
        System.out.println(ageComparator.compare(student1, student2));
    }

}
